package com.peng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peng.pojo.LoginForm;
import com.peng.pojo.Student;
import com.peng.service.StudentService;
import com.peng.mapper.StudentMapper;
import com.peng.utils.MD5;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
* @author dell
* @description 针对表【tb_student】的数据库操作Service实现
* @createDate 2022-05-15 13:39:20
*/
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService{

    @Override
    public Student login(LoginForm loginForm) {
        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Student::getName,loginForm.getUsername());
        queryWrapper.eq(Student::getPassword, MD5.encrypt(loginForm.getPassword()));
        queryWrapper.last("limit 1");
        Student student = baseMapper.selectOne(queryWrapper);
        return student;
    }

    @Override
    public IPage<Student> getStudentByOpr(Integer pageNo, Integer pageSize, String name, String clazzName) {
        Page<Student> studentPage = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(name))
            queryWrapper.like(Student::getName,name);

        if (!StringUtils.isEmpty(clazzName))
            queryWrapper.like(Student::getClazzName,clazzName);
        Page<Student> studentPage1 = baseMapper.selectPage(studentPage, queryWrapper);
        return studentPage1;
    }
}




